﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Milo.Framework
{
	public interface IModelControl<TModel> : IControl
	{
		/// <summary>
		/// Gets or sets the model value.
		/// </summary>
		/// <value>The value.</value>
		TModel Value { get; set; }
		/// <summary>
		/// Links the control to parent control, so that the correct chaining happens. <see cref="Value"/> is disconnected from the Model
		/// </summary>
		/// <param name="name">The name.</param>
		/// <param name="parent">The parent.</param>
		void LinkToParent(string name, IControl parent);
		/// <summary>
		/// Links the control to parent control, so that the correct chaining happens as well as access to the properties the model
		/// control encapsulates.
		/// </summary>
		/// <param name="name">The name.</param>
		/// <param name="parent">The parent.</param>
		/// <param name="valueGetter">The value getter.</param>
		/// <param name="valueSetter">The value setter.</param>
		/// <param name="index">The index.</param>
		void LinkToParent(string name, IControl parent, GetPropertyDelegate<TModel> valueGetter, SetPropertyDelegate<TModel> valueSetter, int index);

		/// <summary>
		/// Returns a <see cref="T:System.String"/> that represents the current control value using the specified mask 
		/// </summary>
		/// <param name="mask">The mask.</param>
		/// <returns></returns>
		string ToString(string mask);
		/// <summary>
		/// Returns a <see cref="T:System.String"/> that represents the current control value using the specified mask,
		/// or a substitute string if it is null or empty
		/// </summary>
		/// <param name="mask">The mask.</param>
		/// <param name="nullOrEmptySubstitution">The null or empty substitution.</param>
		/// <returns></returns>
		string ToString(string mask, string nullOrEmptySubstitution);
	}

	#region generic typed delegates
	public delegate TModel GetPropertyDelegate<TModel>(int index);
	public delegate void SetPropertyDelegate<TModel>(TModel value, int index);
	#endregion
}
